// pages/User/details/details.js
var app = getApp();
var Api = require("../../../api/method.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pop: true,
    currentData: 0,
    shouquan: true,
    qrUrl: "",
    nickName: "",
    directNickName: "",
    accountBalance: "",
    paySource: "",
    directCount: "",
    indirectCount: "",
    kaidan: "",
    directAmount: "",
    indirectAmount: "",
    yongjin: "",
    pageNo: 1,
    buyclass: "",
    sjywy:false
  },
  //获取当前滑块的index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  //账号密码登录
  login: function (e) {
    wx.redirectTo({
      url: "/pages/login/login",
    })
  },
  //业务员我的
  Salesmandetail: function (e) {
    let that = this;
    let list = {
    };
    Api.owner(list, function (err, res) {
      console.log(res.data);
      if (res.data.code == 1) {
        if (res.data.data.nickName == null) {
          that.setData({
            sjywy: true
          })
        };
        that.setData({
          directNickName: res.data.data.directSuperior,
          accountBalance: res.data.data.accountBalance,
          paySource: res.data.data.paySource,
          directCount: res.data.data.directCount,
          indirectCount: res.data.data.indirectCount,
          kaidan: res.data.data.directCount + res.data.data.indirectCount,
          directAmount: res.data.data.directAmount,
          indirectAmount: res.data.data.indirectAmount,
          yongjin: res.data.data.directAmount + res.data.data.indirectAmount
        })
      }
    });
  },
  //业务员购课列表
  ownercourse: function (e) {
    let that = this;
    let list = {
      type: 1,
      pageNo: that.data.pageNo,
      pageSize: 10,
    };
    console.log(list);
    Api.ownercourse(list, function (err, res) {
      console.log(res.data);
      if (res.data.code == 1) {
        if (that.data.pageNo == 1) {
          that.setData({
            buyclass: res.data.data
          })
        } else {
          that.setData({
            buyclass: that.data.buyclass.concat(res.data.data)
          })
        }
        if (res.data.data == "" && that.data.pageNo != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: "none",
            duration: 1500
          })
        }
        wx.hideLoading();
      }
    });
  },
  //同意授权处理
  likesClick: function (e) {
    this.setData({
      shouquan: true
    });
    this.Salesmandetail();
    this.ownercourse();
  },
  //订单详情页
  Details:function(e){
    wx.navigateTo({
      url: "/pages/branch/Details/Details?id=" + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      nickName: wx.getStorageSync("user").nickName
    });
    if (wx.getStorageSync("user")){
      this.Salesmandetail();
      this.ownercourse();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.editTabBar2();    //显示自定义的底部导航
    if (wx.getStorageSync("user")) {
      this.setData({
        shouquan: true
      })
    } else {
      this.setData({
        shouquan: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      pageNo: this.data.pageNo + 1
    });
    this.Course();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})